let searchBox = document.querySelector('#keywords');
let sendBtn = document.querySelector('#send');
let tbody = document.querySelector('tbody');

fetch("https://music.0melon0.cn/search?keywords=${keywords}", {
    method: "GET",// type请求类型
}).then(function (response) {
    return response.json(); //转json格式返回值，解析为可读数据
}).then(function (data) {
    console.log(data); //获取请求成功的结果
    sendBtn.addEventListener('click',function(){
        let keywords = searchBox.value;
        console.log(keywords);
        show();
    })
    function show(){
        data.result.songs.forEach(function (item, idx) {
            let time = moment(item.duration).format('MM:SS')
            tbody.innerHTML += `<tr>
            <td>${item.name}</td>
            <td>${item.artists[0].name}</td>
            <td>${item.album.name}</td>
            <td>${time}</td>  
            </tr>`;
        });
    }
}).catch(function(error){
    console.log(error);//获取请求失败的结果
});
